CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(flash)

MACRO(ADD_SWF SWF MXML VERSION PLAYER)
    SET(FP_10_3 "false")
    IF ((${PLAYER} VERSION_EQUAL "10.3") OR (${PLAYER} VERSION_GREATER "10.3"))
        SET(FP_10_3 "true")
    ENDIF ((${PLAYER} VERSION_EQUAL "10.3") OR (${PLAYER} VERSION_GREATER "10.3"))

    SET(FP_11 "false")
    IF ((${PLAYER} VERSION_EQUAL "11") OR (${PLAYER} VERSION_GREATER "11"))
        SET(FP_11 "true")
    ENDIF ((${PLAYER} VERSION_EQUAL "11") OR (${PLAYER} VERSION_GREATER "11"))

	ADD_CUSTOM_COMMAND(
		OUTPUT
			${SWF}
		COMMAND
		mxmlc ${MXML} -define=CONFIG::FP_10_3,${FP_10_3} -define=CONFIG::FP_11,${FP_11} -swf-version=${VERSION} -target-player=${PLAYER} -output ${SWF}
		DEPENDS
			${MXML}
			${CMAKE_CURRENT_SOURCE_DIR}/main.as
			${CMAKE_CURRENT_SOURCE_DIR}/stresstest.as
			${CMAKE_CURRENT_SOURCE_DIR}/com/rtckit/*.as
		WORKING_DIRECTORY
			${CMAKE_CURRENT_BINARY_DIR}
		COMMENT
			"Building ${SWF} with MXML compiler"
	)

	ADD_CUSTOM_TARGET(
		${SWF}.target
		DEPENDS
			${SWF}
	)
ENDMACRO(ADD_SWF)

ADD_SWF(flashphone_11_0.swf ${CMAKE_CURRENT_SOURCE_DIR}/main.mxml 13 "11.0")
ADD_SWF(flashphone_10_3.swf ${CMAKE_CURRENT_SOURCE_DIR}/main.mxml 12 "10.3")
ADD_SWF(flashphone_10_0.swf ${CMAKE_CURRENT_SOURCE_DIR}/main.mxml 11 "10.2")
ADD_SWF(stresstest.swf ${CMAKE_CURRENT_SOURCE_DIR}/stresstest.mxml 11 "10.2")

ADD_CUSTOM_TARGET(
	flash
	DEPENDS
		flashphone_11_0.swf
	   	flashphone_10_3.swf
		flashphone_10_0.swf
		stresstest.swf
	WORKING_DIRECTORY
		${CMAKE_CURRENT_BINARY_DIR}
)
